require 'test/unit'
require 'random'
require 'Seed'

class TestPlanet < Test::Unit::TestCase
	
	def test_create
		r = RandomGenerator.new(1234)
		a1 = r.generateSequence()
		a2 = r.generateSequence()
		assert_equal(a1, a2)
	end
	
	def test_left_rotate_left_trivial
		assert_equal(0b0, RandomGenerator.rotate_left(0b0))
		assert_equal(0b10, RandomGenerator.rotate_left(0b1))
	end
	
	def test_left_rotate_left_for_simple_values
		assert_equal(0b10, RandomGenerator.rotate_left(0b1))
		assert_equal(0b100, RandomGenerator.rotate_left(0b10))
	end
	
	def test_bit_wraps_around
		assert_equal(1, RandomGenerator.rotate_left(128))
	end
	
	def test_rotation_returns
		assert_equal(254, RandomGenerator.rotate_left(127))
		assert_equal(253, RandomGenerator.rotate_left(254))
		assert_equal(251, RandomGenerator.rotate_left(253))
		assert_equal(247, RandomGenerator.rotate_left(251))
		assert_equal(239, RandomGenerator.rotate_left(247))
		assert_equal(223, RandomGenerator.rotate_left(239))
		assert_equal(191, RandomGenerator.rotate_left(223))
		assert_equal(127, RandomGenerator.rotate_left(191))
	end
	
	def test_twists_returns_to_start_after_eight_steps
		initial_value = 33
		value = initial_value
		8.times { value = RandomGenerator.twist(value) }
		assert_equal(initial_value, value)
	end
	
	def test_seed_tweaking
		seed = Seed.new(3, 4, 5)
		RandomGenerator.tweak_seed(seed)
		assert_equal(4, seed.value1)
		assert_equal(5, seed.value2)
		assert_equal(12, seed.value3)
	end
end